import os
import LiseXML
import Lise
import Error



class LiseDigi(LiseXML.LiseXML):
    """
    Implements the operations related to the file system structure of a LiSe definition

    """

    def __init__(self, lisePath):
        """Arguments:
        lisePath(string) -- LiSe XML file path

        """
        id = os.path.basename(lisePath)
        if id.endswith('.xml'):
            id = id[:-4]
        self.digiFilenames = []
        LiseXML.LiseXML.__init__(self, lisePath)



    def readDigiSubdir(self):
        """Retrieves the list of filenames of the digitised file images

        """
        digiSubdirPath = os.path.join(os.path.dirname(self.lisePath), self.digiSubdir)
        if os.path.exists(digiSubdirPath):
            self.digiFilenames = [i for i in os.listdir(digiSubdirPath) if i.endswith('.jpg')]
        else:
            raise Error.Error(201, 'Digitisations subdirectory not found: ' + 
                              self.digiDirPath)



